<?php

namespace app\api\listener;
use app\common\model\ProductSearch as SearchModel;
use app\common\model\ProductSearchLog;

class ProductSearch
{
    public function handle($data)
    {
        $keyword = $data['keyword'];
        $uid = $data['uid'];
        if($find = SearchModel::where('keyword', $keyword)->find()){
            $find->hot ++;
            $find->save();
        }else{
            SearchModel::create([
                'keyword' => $keyword
            ]);
        }
        ProductSearchLog::create([
            'keyword' => $keyword,
            'uid' => $uid
        ]);
    }
}